package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.service.GenderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/gender")
@Slf4j
public class GenderController {
    @DubboReference
    private GenderService genderService;
    /**
     * 会员性别占比统计
     * @return
     */
    @GetMapping("/getGenderReport")
    public Result getGenderReport(){
        //数据查询统计数据
        List<Map<String,Object>> gendercount = genderService.countByGender();
        log.info("[查询到的数据] data {}",gendercount);
        ArrayList<String> gendernames = new ArrayList<>();
        for (Map<String, Object> elem : gendercount) {
            gendernames.add(String.valueOf(elem.get("name")));
        }
       log.info("[标题数据]data{}",gendernames);
        Map<String,Object> map = new HashMap<>();
        map.put("gendernames",gendernames);
        map.put("gendercount",gendercount);
        log.info("[返回的数据为]data{}",map);
        return new Result(true, MessageConst.GET_MEMBER_NUMBER_REPORT_SUCCESS,map);
    }

    @GetMapping("/getAgeGroup")
    public Result getAgeGroup(){
        List<Map<String, Object>> gendercount = genderService.findByMember();
        log.info("[返回]data{}",gendercount);

        List<String> gendernames = new ArrayList<>();
      for (Map<String, Object> elem : gendercount) {
          gendernames.add(String.valueOf(elem.get("name")));
      }
      Map<String,Object> map = new HashMap<>();
      map.put("gendernames",gendernames);
      map.put("gendercount",gendercount);

        return new Result(true, MessageConst.GET_MEMBER_NUMBER_REPORT_SUCCESS,map);
    }

}
